package com.module.framework.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.module.framework.domain.Book;
import com.module.framework.mapper.*;
import com.module.framework.service.DashboardService;
import com.module.framework.vo.DashboardVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DashboardServiceImpl implements DashboardService {

    @Resource
    private BookMapper bookMapper;

    @Resource
    private UserMapper userMapper;

    @Resource
    private CommentMapper commentMapper;

    @Resource
    private HisLendMapper hisLendMapper;

    @Resource
    private NowLendMapper nowLendMapper;

    @Override
    public DashboardVO getData() {
        DashboardVO dashboardVO = new DashboardVO();
        // 图书数量
        dashboardVO.setBookCount(bookMapper.selectTotalNumberSum());
        // 读者数量
        dashboardVO.setReaderCount(userMapper.selectCount(null));
        //评论数量
        dashboardVO.setCommentCount(commentMapper.selectCount(null));
        // 借阅总数
        dashboardVO.setTotalBorrowed(hisLendMapper.selectCount(null));
        // 借阅中
        dashboardVO.setBorrowedCurrently(nowLendMapper.selectCount(null));

        // 查询分类为经济的借阅数
        QueryWrapper<Book> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("cate_id", 6);
        List<Book> books1 = bookMapper.selectList(queryWrapper1);
        System.out.println(books1);
        dashboardVO.setEconomy(books1.size());

        // 查询分类为文化、科学、教育、体育的借阅数
        QueryWrapper<Book> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("cate_id", 7);
        List<Book> books2 = bookMapper.selectList(queryWrapper2);
        System.out.println(books2);
        dashboardVO.setCultureScienceEducationSports(books2.size());

        // 查询分类语言文字的借阅数
        QueryWrapper<Book> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("cate_id", 8);
        List<Book> books3 = bookMapper.selectList(queryWrapper3);
        dashboardVO.setLanguageLiterature(books3.size());

        // 查询分类为文学的借阅数
        QueryWrapper<Book> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.eq("cate_id", 9);
        List<Book> books4 = bookMapper.selectList(queryWrapper4);
        dashboardVO.setLiterature(books4.size());

        // 查询分类为马克思主义、列宁、毛泽东、邓小平的借阅数
        QueryWrapper<Book> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.eq("cate_id", 1);
        List<Book> books5 = bookMapper.selectList(queryWrapper5);
        dashboardVO.setMarxism(books5.size());

        // 查询分类为哲学、宗教的借阅数
        QueryWrapper<Book> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.eq("cate_id", 2);
        List<Book> books6 = bookMapper.selectList(queryWrapper6);
        dashboardVO.setPhilosophyReligion(books6.size());

        // 查询分类为社会科学的借阅数
        QueryWrapper<Book> queryWrapper7 = new QueryWrapper<>();
        queryWrapper7.eq("cate_id", 3);
        List<Book> books7 = bookMapper.selectList(queryWrapper7);
        dashboardVO.setSocialScience(books7.size());

        // 查询分类为政治、法律的借阅数
        QueryWrapper<Book> queryWrapper8 = new QueryWrapper<>();
        queryWrapper8.eq("cate_id", 4);
        List<Book> books8 = bookMapper.selectList(queryWrapper8);
        dashboardVO.setPoliticsLaw(books8.size());

        // 查询分类为军事的借阅数
        QueryWrapper<Book> queryWrapper9 = new QueryWrapper<>();
        queryWrapper9.eq("cate_id", 5);
        List<Book> books9 = bookMapper.selectList(queryWrapper9);
        dashboardVO.setMilitary(books9.size());

        // 查询分类为艺术的借阅数
        QueryWrapper<Book> queryWrapper10 = new QueryWrapper<>();
        queryWrapper10.eq("cate_id", 10);
        List<Book> books10 = bookMapper.selectList(queryWrapper10);
        dashboardVO.setArt(books10.size());


        return dashboardVO;
    }
}
